﻿@model Controller2.Models.Empresa
@{
    ViewBag.Title = "Cadastro de Empresa";
}
<style type="text/css">
    fieldset
    {
        width: 700px;
        margin: 30px auto;
    }
    .editor-label
    {
        width: 140px;
    }
    #IdEstado
    {
        border: 1px solid #ff0000;
    }
    input[type=text].obrigatorio
    {
        width: 400px;
    }    
    select#IdCidade
    {
        border: 1px solid silver;
    }
</style>
@if (false)
    {
    <script src="../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-ui.js" type="text/javascript"></script>
    <script src="../../Scripts/controller.js" type="text/javascript"></script>
    }
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
<div style="width: 700px; padding: 0; margin: auto auto;">
    @using (Html.BeginForm("Salvar", "Empresa"))
    {
        @Html.ValidationSummary(true)
        <fieldset>
            <legend>Cadastro da Empresa</legend>
            @Html.HiddenFor(model => model.IdEmpresa)
            <div class="editor-label">
                @Html.LabelFor(model => model.DataAbertura, "Data Abertura: ")
            </div>
            <div class="editor-field">                                
                @Html.EditorFor(model => model.DataAbertura)
                @Html.ValidationMessageFor(model => model.DataAbertura)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.NomeEmpresa, "Nome: ")
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(model => model.NomeEmpresa, new { maxlength = "150", @class = "obrigatorio " })
                @Html.ValidationMessageFor(model => model.NomeEmpresa)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.InscricaoEstadual, "Insc. Estadual: ")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.InscricaoEstadual)
                @Html.ValidationMessageFor(model => model.InscricaoEstadual)
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                @Html.LabelFor(model => model.CNPJ, "CNPJ: ")
                @Html.EditorFor(model => model.CNPJ)
                @Html.ValidationMessageFor(model => model.CNPJ)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.Endereco, "Endereço: ")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Endereco)
                @Html.ValidationMessageFor(model => model.Endereco)
                &nbsp;&nbsp;&nbsp;
                @Html.LabelFor(model => model.NumEnd, "Nº: ")
                @Html.EditorFor(model => model.NumEnd)
                @Html.ValidationMessageFor(model => model.NumEnd)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.Complemento, "Complemento: ")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Complemento)
                @Html.ValidationMessageFor(model => model.Complemento)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.Bairro, "Bairro: ")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Bairro)
                @Html.ValidationMessageFor(model => model.Bairro)
                @Html.LabelFor(model => model.CEP, "CEP: ")
                @Html.EditorFor(model => model.CEP)
                @Html.ValidationMessageFor(model => model.CEP)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.IdEstado, "Estado: ")
            </div>
            <div class="editor-field">
                @Html.DropDownListFor(model => model.IdEstado, (IEnumerable<SelectListItem>)ViewBag.Estado, "", new { style = "width: 200px;" })
                @Html.ValidationMessageFor(model => model.IdEstado)
                &nbsp;&nbsp;
                @Html.LabelFor(model => model.IdCidade, "Cidade: ")
                @if (Model.IdCidade > 0)
                {
                    @Html.DropDownListFor(model => model.IdCidade, (IEnumerable<SelectListItem>)ViewBag.Cidade, "", new { style = "width: 252px;" })
                }
                else
                {
                    @Html.DropDownListFor(model => model.IdCidade, (IEnumerable<SelectListItem>)ViewBag.Cidade, "", new { style = "width: 252px;", disabled = "disabled" })
                }
                @Html.ValidationMessageFor(model => model.IdCidade)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.Fone, "Fone: ")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Fone)
                @Html.ValidationMessageFor(model => model.Fone)
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                @Html.LabelFor(model => model.Fax, "Fax: ")
                @Html.EditorFor(model => model.Fax)
                @Html.ValidationMessageFor(model => model.Fax)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.Site, "Site: ")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Site)
                @Html.ValidationMessageFor(model => model.Site)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.Email, "E-mail: ")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Email)
                @Html.ValidationMessageFor(model => model.Email)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.Twitter, "Twitter: ")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Twitter)
                @Html.ValidationMessageFor(model => model.Twitter)
            </div>
        </fieldset>        
        <div id="botoesForm">
            <input type="submit" id="Gravar" value="Gravar" />
        </div>
    }
</div>
<div id="alertaErro" style="display: none">
</div>
<script type="text/javascript">
    $(function () {
        $('input[tipo=integer]').each(function () {
            $(this).rules("remove");
        });
        $('.datepicker').mask("99/99/9999");
        $("#Fone").mask("(99) 9999-9999");
        $("#Celular").mask("(99) 9999-9999");
        $("#CNPJ").mask("99.999.999/9999-99");
        $("#CEP").mask("99999-999");        
        $('#formHide').fadeIn('slow');
        hideLoading();
        if ('@Model.IdEmpresa' > 0) {
            $('#NomePessoa').focus();
        } else {
            $('#DataAbertura').focus();
        }
    });   
    $('#IdEstado').change(function (e) {
        showLoading();
        var idEstado = $('#IdEstado option:selected').val();
        if (idEstado == "") {
            $('#IdCidade').empty();
            $('#IdCidade').attr('disabled', 'disabled');
        } else {
            $('#IdCidade').empty();
            $('#IdCidade').append('<option>Carregando...</option>');
            var url = '@Url.Action("CarregarComboCidade", "Empresa")';
            $.post(url, { idEstado: idEstado }, function (dados) {
                $('#IdCidade').empty();
                $.each(dados, function (index, cidade) {
                    $('#IdCidade').append('<option value="' + cidade.Value + '">' + cidade.Text + '</option>');
                });
                $('#IdCidade').removeAttr('disabled').css("border", "1px solid silver").focus();
            });
        }
        hideLoading();
    });
    $('.datepicker').blur(function () {
        if (!validaData(this)) {
            $(this).focus();
        }
    });
</script>
